﻿using System.Collections.Generic;
using Engine;
using Engine.Graphics;
using Game;

namespace MFTrain
{
    public class MFTrainBlock : Block
    {
        public const int Index = 544;

        public BlockMesh m_standaloneBlockMesh = new BlockMesh();

        public BlockMesh breakerMesh = new BlockMesh();

        public Texture2D texture;

        public override void Initialize()
        {
            Model model = ContentManager.Get<Model>("MF/Train/Train");
            Model model2 = ContentManager.Get<Model>("MF/Train/TrainBreaker");
            texture = ContentManager.Get<Texture2D>("MF/Train/Train");
            Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Cylinder").ParentBone);
            m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Cylinder").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.4f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
            m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Cylinder").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.4f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: false, Color.White);
            Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model2.FindMesh("TrainBreaker").ParentBone);
            breakerMesh.AppendModelMeshPart(model2.FindMesh("TrainBreaker").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateScale(1.5f) * Matrix.CreateTranslation(0f, -0.1f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
            breakerMesh.AppendModelMeshPart(model2.FindMesh("TrainBreaker").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateScale(1.5f) * Matrix.CreateTranslation(0f, -0.1f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: false, Color.White);
            base.Initialize();
        }

        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            int num = Terrain.ExtractData(value);
            int num2 = num;
            if (num2 == 1)
            {
                BlocksManager.DrawMeshBlock(primitivesRenderer, breakerMesh, texture, color, 1f * size, ref matrix, environmentData);
            }
            else
            {
                BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, texture, color, 1f * size, ref matrix, environmentData);
            }
        }

        public override string GetCraftingId(int value)
        {
            switch (Terrain.ExtractData(value))
            {
                case 0:
                    return "mftrain";
                case 1:
                    return "mfbreaker";
                default:
                    return base.GetCraftingId(value);
            }
        }

        public override IEnumerable<int> GetCreativeValues()
        {
            yield return Terrain.MakeBlockValue(544, 0, 0);
            yield return Terrain.MakeBlockValue(544, 0, 1);
        }

        public override string GetDescription(int value)
        {
            switch (Terrain.ExtractData(value))
            {
                case 0:
                    return base.GetCraftingId(value);
                case 1:
                    return "拦车器";
                default:
                    return base.GetCraftingId(value);
            }
        }

        public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
        {
            switch (Terrain.ExtractData(value))
            {
                case 0:
                    return "蒸汽机车";
                case 1:
                    return "拦车器";
                default:
                    return base.GetCraftingId(value);
            }
        }

    }
}